package day16;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

/**
 * 扑克牌大小
 */

/**
 * 基本规则:
 * (1)输入每手牌可能是个子、对子、顺子(连续5张)、三个、炸弹(四个）和对王中的一种，不存在其他情况，由输入保证两手牌都是合法的，顺子已经从小到大排列;
 * (2)除了炸弹和对王可以和所有牌比较之外，其他类型的牌只能跟相同类型的存在比较关系(如，对子跟对子比较，三个跟三个比较)，不考虑拆牌情况(如:将对子拆分成个子);
 * (3)大小规则跟大家平时了解的常见规则相同，个子、对子、三个比较牌面大小;顺子比较最小牌大小;炸弹大于前面所有的牌，炸弹之间比较牌面大小;对王是最大的牌;
 * (4)输入的两手牌不会出现相等的情况。数据范围:字符串长度:3<s≤ 10
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //输出总牌
        String cards = scanner.nextLine();
        //从"-"分割
        String[] another = cards.split("-");
        //对"-"左右两边分割,主要以" "分割
        //左手牌
        String[] one = another[0].split(" ");
        //右手牌
        String[] two = another[1].split(" ");
        plan(one,two,another);
    }

    private static void plan(String[] one, String[] two, String[] another) {
        //用map记录牌的数量,主要区分炸和三带一
        Map<String,Integer> mapone = new HashMap<>();
        Map<String,Integer> maptwo = new HashMap<>();

        for (int i = 0; i < one.length; i++) {
            mapone.put(one[i], mapone.getOrDefault(one[i],0) + 1);
        }
        for (int i = 0; i < two.length; i++) {
            maptwo.put(two[i], maptwo.getOrDefault(two[i],0) + 1);
        }

        if (one.length == 1 && two.length == 1){
            //单牌的情况
            if (Objects.equals(one[0], "JOKER")){
                System.out.println(another[0].toString());
                return;
            }else if (two[0].equals("JOKER")){
                System.out.println(another[1].toString());
                return;
            }else if (Objects.equals(one[0], "joker")){
                System.out.println(another[0].toString());
                return;
            }else if (two[0].equals("joker")){
                System.out.println(another[1].toString());
                return;
            }else {
                //两个都不包含大小王
                if (one[0].compareTo(two[0]) > 0){
                    System.out.println(another[0].toString());
                    return;
                }else {
                    System.out.println(another[1].toString());
                    return;
                }
            }
            //含有王炸的情况
        }else if (one.length == 2 && two.length != 2 && (one[0].equals("joker") && one[1].equals("JOKER"))){
            System.out.println(another[0].toString());
            return;
        }else if (two.length == 2 && one.length != 2 && (two[0].equals("joker") && two[1].equals("JOKER"))){
            System.out.println(another[1].toString());
            return;
            /*****************************************************************************************************/
        }else{
            //含有炸弹的情况
            if (mapone.get(one[0]) == 4 && maptwo.get(two[0]) != 4){
                System.out.println(another[0].toString());
                return;
            }else if (mapone.get(one[0]) != 4 && maptwo.get(two[0]) == 4){
                System.out.println(another[1].toString());
                return;
            }else if (mapone.get(one[0]) == 4 && maptwo.get(two[0]) == 4){
                //都是炸弹的比较
                if (one[0].compareTo(two[0]) > 0){
                    System.out.println(another[0].toString());
                    return;
                }else {
                    System.out.println(another[1].toString());
                    return;
                }
                /*****************************************************************************************************/
            } else if (one.length >= 2 && two.length >= 2){
                //三带一的情况
                if ((mapone.get(one[0]) == 3 || mapone.get(one[1]) == 3) && (mapone.get(one[0]) != 3 || mapone.get(one[1]) != 3)){
                    System.out.println("ERROR");
                    return;
                }else if ((mapone.get(one[0]) != 3 || mapone.get(one[1]) != 3) && (mapone.get(one[0]) == 3 || mapone.get(one[1]) == 3)){
                    System.out.println("ERRORe");
                    return;
                }else if (one.length == 3 && two.length == 3 && mapone.get(one[0]) == 3 && maptwo.get(two[0]) == 3){
                    //都是三带一的比较
                    if (one[0].compareTo(two[0]) > 0){
                        System.out.println(another[0].toString());return;
                    }else {
                        System.out.println(another[1].toString());return;
                    }
                    /*****************************************************************************************************/
                } else {
                    //对子的情况
                    if (mapone.get(one[0]) == 2 && one.length == 2 && two.length != 2){
                        System.out.println("ERROR");return;
                    }else if (maptwo.get(two[0]) == 2 && two.length == 2 && one.length != 2){
                        System.out.println("ERROR");return;
                    }else if (one.length == 2 && two.length == 2 && mapone.get(one[0]) == 2 && maptwo.get(two[0]) == 2){
                        //两个都是对子的情况
                        if (one[0].compareTo(two[0]) > 0){
                            System.out.println(another[0].toString());return;
                        }else {
                            System.out.println(another[1].toString());return;
                        }
                        /*****************************************************************************************************/
                    }else if (one.length == two.length && one.length > 4){
                        //顺子 + 连对的情况
                        if (Integer.parseInt(one[0]) - Integer.parseInt(two[0]) > 0){
                            System.out.println(another[0].toString());return;
                        }else {
                            System.out.println(another[1].toString());return;
                        }
                        /*****************************************************************************************************/
                    }
                }
            }
        }
        System.out.println("ERROR");
    }

}